import useLatest from "../useLatest";
import React, { useEffect } from "react";

/**
 * https://ahooks.js.org/zh-CN/hooks/use-unmount
 * 在组件卸载（unmount）时执行的 Hook。
 */
function useUnmount(fn) {
  const fnRef = useLatest(fn);
  useEffect(() => {
    return () => {
      fnRef.current();
    };
  }, []);
}
export default useUnmount;
